package com.gp.study.mybatis;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class GpMapperProxy implements InvocationHandler {
	
	private GpSqlSession sqlSession;
	
	public GpMapperProxy(GpSqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		
		//如何调用 sqlsession.selectOne() 根据 statementId 获取 sql
		// statementId = interfaceName.methodName
		String interfaceName = method.getDeclaringClass().getName();
		String methodName = method.getName();
		String statementId = interfaceName+"."+methodName;
		return sqlSession.selectOne(statementId,args[0]);
	}

}
